<!-- 研究报告 -->
<template>
    <div
        class="report"
        v-loading="loading"
        element-loading-text="正在加载..."
        element-loading-spinner="el-icon-loading"
        element-loading-background="rgba(9, 9, 16, 1)"
    >
        <div v-if="!loading">
            <!-- 公司研究 -->
            <yn-com-comTitle name="公司研究"></yn-com-comTitle>
            <yn-rep-reportList
                :data="company"
                :infoType="companyInfoType"
                type="company"
                title="公司研究"
                :total="companyTotal"
                @page="onPage"
            ></yn-rep-reportList>
            <!-- 行业研究 -->
            <yn-com-comTitle class="mt15" name="行业研究"></yn-com-comTitle>
            <yn-rep-reportList
                :data="industry"
                :infoType="industryInfoType"
                type="industry"
                title="行业研究"
                :total="industryTotal"
                @page="onPage"
            ></yn-rep-reportList>
        </div>
    </div>
</template>

<script>
import {report, tradereport} from "../script/api";
import dayjs from "dayjs";

export default {
    data() {
        return {
            company: [], //公司研究
            companyTotal: 0,
            companyInfoType: "1",
            industry: [], //行业研究
            industryTotal: 0,
            industryInfoType: "2",
            loading: true,
        };
    },
    mounted() {
        this.reportCompany();
        this.reportIndustry(); //首次加载列表
    },
    methods: {
        async reportCompany() {
            const res = await report({infoType: this.companyInfoType});
            if (res.status == 1) {
                this.loading = false;
                // this.company = res ? res.pageData : [];
                // this.companyTotal = res ? res.total : 0;
                // this.company = res ? res.data.content : [];
                this.company = res.data.content.map((item) => {
                    item.declareDate = dayjs(item.declareDate).format("YYYY-MM-DD");
                    return item;
                });
                this.companyTotal = res ? res.data.totalElements : 0;
            }
        },
        //行业报告
        async reportIndustry() {
            const res = await tradereport({infoType: this.industryInfoType});
            if (res.status == 1) {
                // this.industry = res ? res.data.content : [];
                this.industry = res.data.content.map((item) => {
                    item.declareDate = dayjs(item.declareDate).format("YYYY-MM-DD");
                    item.rptTitle = item.title;
                    return item;
                });
                this.industryTotal = res ? res.data.totalElements : 0;
            }
        }, //分页
        async onPage(ops) {
            const res = await report({
                infoType: ops.infoType,
                pageNum: ops.page - 1,
            }); //公司新闻
            if (ops.infoType == 1) {
                this.company = res.data.content.map((item) => {
                    item.declareDate = dayjs(item.declareDate).format("YYYY-MM-DD");
                    return item;
                });
                this.companyTotal = res.data.totalElements;
            } //公司公告
            if (ops.infoType == 2) {
                this.industry = res.data.content.map((item) => {
                    item.declareDate = dayjs(item.declareDate).format("YYYY-MM-DD");
                    console.log(item, "item");
                    item.rptTitle = item.rptTitle ? item.rptTitle : item.title;
                    return item;
                });
                this.industryTotal = res.data.totalElements;
            }
        },
    },
};
</script>
<style lang="scss" scoped></style>
